/*----------------------------------------------------------------------------
 * osObjects.h: CMSIS-RTOS global object definitions for an application
 *----------------------------------------------------------------------------
 *
 * This header file defines global RTOS objects used throughout a project
 *
 * #define osObjectsPublic indicates that objects are defined; without that
 * definition the objects are defined as external symbols.
 *
 *--------------------------------------------------------------------------*/


#ifndef __osObjects
#define __osObjects


#ifdef osObjectsCreat
#define OBJ_EXT  
#else
#define OBJ_EXT extern 
#endif


#include "cmsis_tx.h"
#include "common.h"
     
//#include "cmsis_os.h"               // CMSIS RTOS header file

#define OS_TICK_FREQ       TX_TIMER_TICKS_PER_SECOND
#define ms_ticks(x)        (x*OS_TICK_FREQ/1000)


//--obj define
#define os_mutex_define
#define os_mutex_creat
#define os_mutex_obj_link

extern char * tx_err_txt[];

#ifdef DEBUG
void os_err_print(uint16_t os_err, char *file, int line);
#define os_api_exe_check() os_err_print(os_err, __FILE__, __LINE__)
#else
#define os_api_exe_check()
#endif

// global 'thread' functions ---------------------------------------------------

int os_thread_init(void);
int os_obj_creat(void);
int os_thread_creat (void);

/*
********************************************************************************
*                       任务优先级，数值越小优先级越高
********************************************************************************
*/
#define  APP_CFG_TASK_START_PRIO                          2u
#define  APP_CFG_TASK_FLASH_PRIO                          5u
#define  APP_CFG_TASK_USB_PRIO                            12u
#define  APP_CFG_TASK_IDLE_PRIO                           30u

/*
********************************************************************************
*                                静态全局变量
********************************************************************************
*/

typedef struct
{
	TX_THREAD   tcb_app_task_system;           //for modbus and systask
	uint64_t    stk_app_task_system[1024 / 8];
    osThreadId  tid_systask;

	TX_THREAD   tcb_task_idle;               //for idle
	uint64_t    stk_task_idle[512 / 8];
    osThreadId  tid_idle;
    
    TX_THREAD   tcb_task_usb;               //for usb
	uint64_t    stk_task_usb[2048 / 8];
    osThreadId  tid_usb;
    
    TX_THREAD   tcb_flash;
	uint64_t    stk_task_flash[768 / 8];
	osThreadId  tid_flash;
    
    // global 'enent' -----------------------------------------------------
    TX_EVENT_FLAGS_GROUP event_mb;
    osEventId  eid_mb;

	// global 'semaphores' -----------------------------------------------------
    
	// global 'message queues' -------------------------------------------------
    TX_QUEUE que_flash_cb;
    osQueneId qid_flash;
    uint32_t que_flash_buff[16];


} os_obj_type;

OBJ_EXT os_obj_type  os_obj;                                  // thread id

#endif  // __osObjects
